package com.lq.createPattern.singleton.type5;

public class SingletonTest05 {
    public static void main(String[] args) {
        System.out.println("懒汉式 线程安全写法 同步代码块 不能起到线程同步的作用");
        Singleton singleton = Singleton.getInstance();
       Singleton singleton1 = Singleton.getInstance();
        System.out.println(singleton1 == singleton);
        System.out.println(singleton1.hashCode());
        System.out.println(singleton.hashCode());
    }
}

class Singleton{
    private Singleton() {};
    private static Singleton instance;

    public static Singleton getInstance() {
        if(null==instance){
            synchronized (Singleton.class){
                instance=new Singleton();
            }
        }
        return instance;
    }
}